package vip.xiaonuo.common.util;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zjt
 * @description 发送企业微信机器人消息
 * @date 2025/2/26 10:52
 */
@Slf4j
public class CommonQyRobotUtil {

    public static void sendMessage(String message) {
        HttpRequest httpPost = HttpUtil.createPost("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3d1c101f-2b26-4645-b408-f3c631d16ae9");
        httpPost.header(Header.CONTENT_TYPE, "application/json");
        Map<String, String> params = new HashMap<>();
        params.put("content", "测试机器人");
        httpPost.body(JSON.toJSONString(params));
        String body = "";
        try (HttpResponse execute = httpPost.execute()) {
            body = execute.body();
            log.info("调用企业微信机器人接口结束:{}", body);
        } catch (Exception e) {
            log.error("调用企业微信机器人接口出错:{}", e.getMessage());
        }
    }
}
